// function ban(){
//     var shu ;
//     var node = $('#tt').tree('getSelected');
//     if (node){
//         var s = node.text;
//         if (node.attributes){
//             s += ","+node.attributes.p1+","+node.attributes.p2;
//         }
//         shu = s;
//     }
//     console.log("树："+shu);
//     // var shi = $("#test6").val();
//     // console.log("时间："+shi);
//     var type = $("#type").val();
//     console.log("状态"+type)
//
//     var men = $("#men").val();
//     console.log("选择"+men);
//
//     $.post("../house/list",{"shu":shu,"type":type,"number":men,"pageNumber":0,"pageSize":2},function(){
//
//     })
//
// }


$(function () {

    $('#men').selected({
        maxHeight: '400px'
    });

        $('#table').bootstrapTable({
        url: '${pageContext.request.contextPath}/../../house/list',
        columns: [
            {
                field: 'id',
                title: 'id',
                visible : false,
            },{
                field: 'doornumber',
                title: '房屋门牌号'
            }, {
                field: 'typeb.id',
                title: '房屋状态',
                formatter: function (value, row, index) {
                    if (row.typeb.id == 1) {
                        return "空闲";
                    } else {
                        return "已售";
                    }
                }

            },{
                field: 'userdetails.name',
                title: '姓名',
                // visible : false,
            },
            {
                field: 'userdetails.phone',
                title: '手机号',
                // visible : false,
            },
            {
                field: 'userdetails.rundate',
                title: '入住时间',
                formatter: function (value, row, index) {
                    if(row.userdetails!=null){
                        //console.log(row.userdetails[0].name);
                        if(row.userdetails.name!=null){
                            if(row.userdetails.rundate==null) {
                                return "未入住";
                            }else{
                                return row.userdetails.rundate;
                            }
                        }
                    }
                },

            },{
                field: 'userdetails.sfz',
                title: '身份证号码',
                // visible : false,
            },{
                field: 'userdetails.property.name',
                title: '产权',
                // visible : false,
            },
             {
                field: 'sale.name',
                title: '楼'
            }, {
                field: 'danyuan.name',
                title: '单元'
            }, {
                field: 'floor',
                title: '层数'
            }, {
                field: 'huxing.name',
                title: '户型'
            }, {
                field: 'direction.name',
                title: '房屋朝向'
            }, {
                field: 'measure',
                title: '平米',
                formatter: function (value, row, index) {
                    var jia = row .measure+"平方米";
                    return jia;
                }
            },{
                field:'remark',
                title:'简介'
            }
        ],onDblClickRow: function (row, $element, field) {
            // 清空

            $("#name").val("");
            $("#money").val("");
            $("#date").val("");
            $("#xuan").val(1);
            $("#sfz").val("");
            $("#uname").val("");
            $("#phone").val("");
            $("#remark").val("");
            $("#yin").val("");
            $("#yin2").val("");

            //$("#myModal2").modal('show');
            $('#your-modal').modal(open);
            $("#xx").text("百家小区"+row.sale.name+""+row.danyuan.name+""+row.doornumber+"号");
            $("#type1").text(row.typeb.name);
            $("#huxing").text(row.huxing.name);
            $("#chaoxiang").text(row.direction.name);
            $("#mianji").text(row.measure+"平方米");
            $("#yin2").val(row.id);



            //$("#yin3").val(row.userdetails.);
            //console.log(row.userdetails==undefined)


            if(row.userdetails==undefined){
                $("#yin3").val(1);
            }else{
                $("#yin3").val(2);
            }




            // 人
            if(row.userdetails==null){
                $("#name").val(row.doornumber);
                $("#yin2").val(row.id);
            }else{
                var c;
                $.ajax({
                    type : "post",
                    url : "${pageContext.request.contextPath}/../../salesrecord/quan",
                    async : false,
                    data : {
                        "number" : row.doornumber
                    },
                    datatype : "json",
                    success : function(result) {
                        c = eval(result);
                    }
                });

                $("#name").val(row.doornumber);
                $("#money").val(c.money);
                $("#date").val(c.kdate);
                $("#xuan").val(c.chanquan);
                $("#sfz").val(c.sfz);
                $("#uname").val(c.name);
                $("#phone").val(c.phone);
                $("#remark").val(c.remark);
                $("#yin").val(c.id);
                $("#yin2").val(row.id);
            }
        },
        contentType:"application/x-www-form-urlencoded",
        queryParamsType: '',
        //修改分页的默认对数
        //offset,limit
        height: 700,
        pageNumber: 1,
        pageSize: 15,
        pagination:true,
        queryParams: queryParams,
        sidePagination:'server',
    });
})

function queryParams(params) {
    var shu ;
    var node = $('#tt').tree('getSelected');
    if (node){
        var s = node.text;
        if (node.attributes){
            s += ","+node.attributes.p1+","+node.attributes.p2;
        }
        shu = s;
    }
    var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
        'pageSize': params.pageSize,  //页面大小
        'pageNumber': params.pageNumber, //页码
        'shu':shu,
        'type' :$ ('#typexuan').val(),
        'number':$("#men").val(),
    };
    return temp;
};


function search() {
    var opt = $("#table").bootstrapTable('getOptions');

    var shu ;
    var node = $('#tt').tree('getSelected');
    if (node){
        var s = node.text;
        if (node.attributes){
            s += ","+node.attributes.p1+","+node.attributes.p2;
        }
        shu = s;
    }
    var type = $("#typexuan").val();
    var men = $("#men").val();

    $.post('${pageContext.request.contextPath}/../../house/list', {
        'shu':shu,
        'type': type,
        'number':men,
        'pageSize': opt.pageSize,
        'pageNumber': 1
    }, function (data) {

        //重新给table绑定数据
        $("#table").bootstrapTable("load", data);
    });
}

function ti1() {
    var name = $("#name").val();
    var money = $("#money").val();
    var date = $("#date").val();
    var xuan = $("#xuan").val();
    var sfz = $("#sfz").val();
    var uname = $("#uname").val();
    var phone = $("#phone").val();
    var remark = $("#remark").val();
    var yin = $("#yin").val();
    var yin2 = $("#yin2").val();
    if(name==""){
        sweetAlert("合同编号不能为空","请输入合同编号","error");
    }else if(money==""){
        sweetAlert("金额不能空","请输入金额","error");
    }else if(date==""){
        sweetAlert("时间不能为空",'请选择时间',"error");
    }else if(xuan==""){
        sweetAlert("必须选择产权",'请选择产权',"error");
    }else if(sfz==""){
        sweetAlert("身份证号码不能为空",'请输入身份证号码',"error");
    }else if(uname==""){
        sweetAlert("住户姓名不能为空",'请输入住户姓名',"error");
    }else if(phone == ""){
        sweetAlert("手机号不能为空",'请输入手机号',"error");
    }else if(yin==""){
        yin=-1;
    }

    var yin3 = $("#yin3").val();




    if(yin3==1){
        $.post("${pageContext.request.contextPath}/../../salesrecord/add",
            {"id":yin,"number":name,"money":money,"kdate":date,"zdate":"3018-05-04","chanquan":xuan,"sfz":sfz,"name":uname,"phone":phone,"house.id":yin2,"remark":remark},function (date) {
                $('#your-modal').modal(close);
                $.post("${pageContext.request.contextPath}/../../house/upd1",
                    {"number":name,"yin":yin2},function (date) {
                        $("#table").bootstrapTable("load",date);
                        sweetAlert("成功！")
                    })
            })

        $.post("${pageContext.request.contextPath}/../../lin/a",{"id":yin2},function(){

        })
    }else if(yin3==2){
        $.post("${pageContext.request.contextPath}/../../salesrecord/add",
            {"id":yin,"number":name,"money":money,"kdate":date,"zdate":"3018-05-04","chanquan":xuan,"sfz":sfz,"name":uname,"phone":phone,"house.id":yin2,"remark":remark},function (date) {
                $('#your-modal').modal(close);
                $.post("${pageContext.request.contextPath}/../../house/upd1",
                    {"number":name,"yin":yin2},function (date) {
                        $("#table").bootstrapTable("load",date);
                        sweetAlert("成功！")
                    })
            })
    }












}
